import torch
import numpy as np

np_data = np.arange(6).reshape((2,3))
torch_data = torch.from_numpy(np_data)
torch_to_array = torch_data.numpy()
print(np_data)
print(torch_data)
print(torch_to_array)


c = torch.tensor(np.array([[-1, -2], [2, -4]]))
c = torch.abs(c)
print(c)

#####
data = [[1, 2], [3, 4]]
tensor = torch.tensor(data, dtype=torch.float32)
data = np.array(data)
print("=====")
print(tensor)
print(data)
#numpy和torch中的矩阵相乘
print("=====")
print(np.matmul(data, data))
print(torch.mm(tensor, tensor))

#使用.dot也可以矩阵相乘
print("=====")
data = np.array(data)
print(data.dot(data))
tensor = torch.tensor([2])
print(tensor.dot(tensor)) #注意俩者的dot不一样，tensor的dot把结果展平相加


